package demo4;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何华树
 * Date: 2024-08-31
 * Time: 11:47
 */
public class Test {
    public static Animal func3() {
        Cat cat = new Cat("mimi",6,8.0);
        return cat;
    }
    public static void func2(Animal animal2) {
        System.out.println(animal2.name);
    }
    public static void main1(String[] args) {
        //向上转型的三种方式
        //1.直接赋值
        Animal animal1 = new Dog("旺财",3,9.0);
        animal1.eat();
//        animal1.bark();//向上转型的缺点，无法访问子类的特有方法，只能访问父类的方法。
        //2.方法传参
        Dog dog = new Dog("大黄",4,10.9);
        func2(dog);
        //3.方法的返回值
        Animal animal3 = func3();
        System.out.println(animal3.name);
//        animal3.mimi();
    }
}
